package m4;

import com.rabbitmq.client.*;

import java.util.Scanner;

public class Producer4 {
    public static void main(String[] args) throws Exception{
        //连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672); //默认端口可以不用设置
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection(); //连接
        Channel c = con.createChannel(); //通道
        //创建Fanout类型交换机：logs
        c.exchangeDeclare("logs", BuiltinExchangeType.FANOUT/*"fanout"*/);
        //向logs交换机发送消息
        while (true){
            System.out.print("输入消息： ");
            String s = new Scanner(System.in).nextLine();
            //第二个参数对fanout交换机无效
            c.basicPublish("logs","", null,s.getBytes("UTF-8"));
        }
    }
}
